<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/view/conf/farmtag.tld" prefix="PF"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fun"%>
<style>
<!--
.list-group {
	margin-top: 8px;
}

.list-group .list-group-item {
	background-color: #ffffee;
}
-->
</style>

<div class="widget-box shadow-box">
	<div class="title">
		<h3>
			<i class="glyphicon glyphicon-star"></i>小组留言
		</h3>
	</div>
	<div class="stream-list p-stream">
		<div class="stream-item" id="loop-30" style="padding: 4px;">
			<c:forEach items="${message.resultList}" var="node">
				<div class="col-sm-12">
					<hr class="hr_split" />
				</div>
				<div class="col-sm-12 doc_node">
					<div class="media message_boxunit">
						<a class="pull-left"
							href="webuser/PubHome.do?userid=${node.CUSER }"
							style="max-width: 200px; text-align: center;"
							title="${node.CUSERNAME }"> <img
							class="img-circle side_unit_author_img_min"
							alt="${node.CUSERNAME}" src="<PF:basePath/>${node.IMGURL}">
							<br />
						</a>
						<div class="media-body">
							<div class="side_unit_info">
								<div class="side_unit_info">
									<span class="side_unit_info"> <a
										href="webuser/PubHome.do?userid=${node.CUSER }">${node.CUSERNAME }</a>
										${node.CTIME }
									</span>
								</div>
								<div class="doc_node_content" style="margin: 4px;">${node.CONTENT}</div>
								<div class="side_unit_info">
									<c:if test="${USEROBJ!=null}">
										<button id="approveOf${node.ID }" type="button"
											class="btn btn-default btn-xs"
											onclick="approveOf('${node.ID }')">赞同(${node.PRAISNUM})</button>
										<button id="oppose${node.ID }" type="button"
											class="btn btn-default btn-xs"
											onclick="oppose('${node.ID }')">反对(${node.CRITCISMNUM})</button>
										<button type="button" onclick="replyClick('${node.ID}')"
											class="btn btn-info btn-xs">回复</button>
									</c:if>
									<c:if test="${isadmin}">
										<button type="button" onclick="delClick('${node.ID}')"
											class="btn btn-danger btn-xs">刪除留言</button>
									</c:if>
								</div>
								<div class="side_unit_info message_reply_box"
									id="reply${node.ID}box" style="margin-top: 4px;">
									<div class="form-inline">
										<input type="hidden" id="reply${node.ID}id" name="id"
											value="${node.ID}" /> <input type="hidden"
											id="reply${node.ID}groupid" name="groupid"
											value="${node.APPID}" />
										<div class="form-group">
											<input type="text" id="reply${node.ID}content" name="content"
												class="form-control" style="width: 200px;">
										</div>
										<button id="${node.ID}" class="btn btn-defaul replybutton">回复</button>
									</div>
								</div>
							</div>
							<div class="side_unit_info">
								<ul class="list-group">
									<c:forEach var="replay" items="${node.replys }">
										<li class="list-group-item"><span class="side_unit_info">
												<a href="webuser/PubHome.do?userid=${replay.CUSER}"
												class="color_a"> ${replay.CUSERNAME }</a> <PF:FormatTime
													date="${replay.CTIME}" yyyyMMddHHmmss="yyyy-MM-dd HH:mm" />
										</span>： <c:if test="${isadmin}">
												<a type="button" onclick="delClick('${replay.ID}')">刪除留言</a>
											</c:if> <br /> <br />${replay.CONTENT }</li>
									</c:forEach>
								</ul>
							</div>
						</div>
					</div>
				</div>
			</c:forEach>
			<div style="clear: both;">&nbsp;</div>
			<jsp:include page="includeCommentsForm.jsp"></jsp:include>
		</div>
	</div>
</div>
<script type="text/javascript">
	$(function() {
		$('.message_reply_box').hide();
		$('.message_operate_box').hide();
		//$(".message_boxunit").mouseenter(function() {
		//	$('.message_operate_box', this).show();
		//});
		//$(".message_boxunit").mouseleave(function() {
		//	$('.message_operate_box').hide();
		//	$('.message_reply_box').hide();
		//});
		groupmessage_pagenum = '${num}'
		//-----------------------------
		//回复留言
		$('.replybutton').click(function() {
			var id = $('#reply' + $(this).attr('id') + 'id').val();
			var groupid = $('#reply' + $(this).attr('id') + 'groupid').val();
			var content = $('#reply' + $(this).attr('id') + 'content').val();
			$.post('webgroupmessage/reply.do', {
				'id' : id,
				'groupid' : groupid,
				'content' : content
			}, function(flag) {
				var flag = $.parseJSON(flag);
				if (flag.STATE == 1) {
					alert(flag.MESSAGE);
				}
				if (flag.STATE == 0) {
					loadMessagePage(groupmessage_pagenum);
				}
			});
		});

	});
	//管理员刪除留言
	function delClick(id) {
		if (confirm("该留言删除后无法恢复，是否继续删除？")) {
			$.post('webgroupmessage/del.do', {
				'num' : 1,
				'groupid' : '${groupid}',
				'id' : id
			}, function(flag) {
				var flag = $.parseJSON(flag);
				if (flag.STATE == 1) {
					alert(flag.MESSAGE);
				}
				if (flag.STATE == 0) {
					loadMessagePage(groupmessage_pagenum);
				}
			});
		}
	}
	function replyClick(messageId) {
		$('.message_reply_box').hide();
		$('#reply' + messageId + 'box').show();
	}
	//赞同
	function approveOf(id) {
		$.ajax({
			type : "post",
			url : "webgroupmessage/approveOf.do?id=" + id,
			dataType : "json",
			async : false,
			success : function(obj) {
				$("#approveOf" + id).html(
						"赞同(" + obj.farmDocmessage.praisnum + ")");
			}
		});

	}

	//反对
	function oppose(id) {
		$.ajax({
			type : "post",
			url : "webgroupmessage/oppose.do?id=" + id,
			dataType : "json",
			async : false,
			success : function(obj) {
				$("#oppose" + id).html(
						"反对(" + obj.farmDocmessage.critcismnum + ")");
			}
		});
	}
</script>